﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.ComponentModel;
using System.Data;
using System.Windows.Forms;


namespace libDAL
{
    public class clsAdjustOSDateTime : IDisposable
    {
        public struct MySysDataTime
        {
            public short Year;
            public short Month;
            public short Day;

            public short Hour;
            public short Minute;
            public short Second;
        };

        [DllImport("kernel32.dll", EntryPoint = "GetSystemTime", SetLastError = true)]
        public extern static void Win32GetSystemTime(ref MySysDataTime sysTime);

        [DllImport("kernel32.dll", EntryPoint = "SetSystemTime", SetLastError = true)]
        public extern static bool Win32SetSystemTime(ref MySysDataTime sysTime);

        public void set_SystemTime(DateTime dt)
        {
            MySysDataTime NewDataTime = new MySysDataTime();

            NewDataTime.Year = (short)dt.Year;
            NewDataTime.Month = (short)dt.Month;
            NewDataTime.Day = (short)dt.Day;
            NewDataTime.Hour = (short)dt.Hour;
            NewDataTime.Minute = (short)dt.Minute;
            NewDataTime.Second = (short)dt.Second;

            Win32SetSystemTime(ref NewDataTime);

            MySysDataTime MyCurrentDateTime = new MySysDataTime();
            Win32GetSystemTime(ref MyCurrentDateTime);
            MessageBox.Show("This is  " + MyCurrentDateTime.Month + " of " + MyCurrentDateTime.Year);
            
        }

        public void Dispose()
        {
            GC.Collect();
           // throw new NotImplementedException();
        }
    }
}
